package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketCollect;
import com.cskaoyan.market.db.domain.MarketCollectExample;
import com.cskaoyan.market.db.mapper.MarketCollectMapper;
import com.cskaoyan.market.util.MybatisUtils;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminCollectServiceImpl implements AdminCollectService {

    @Override
    public List<MarketCollect> list(final String page, final String limit, final String sort, final String order, final String userId, final String valueId) {
        SqlSession session = MybatisUtils.getSession();
        MarketCollectMapper marketCollectMapper = session.getMapper(MarketCollectMapper.class);
        MarketCollectExample marketCollectExample = new MarketCollectExample();
        MarketCollectExample.Criteria criteria = marketCollectExample.createCriteria();

        if (!StringUtils.isEmpty(userId)) {
            criteria.andUserIdEqualTo(Integer.parseInt(userId));
        }
        if (!StringUtils.isEmpty(valueId)) {
            criteria.andValueIdEqualTo(Integer.parseInt(valueId));
        }

        marketCollectExample.setOrderByClause(sort + " " + order);

        PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));
        List<MarketCollect> marketCollectList = marketCollectMapper.selectByExample(marketCollectExample);
        session.commit();
        session.close();
        return marketCollectList;
    }

    @Override
    public List<MarketCollect> userIdList(final String page, final String limit, final String sort, final String order, final String userId) {
        return null;
    }

    @Override
    public List<MarketCollect> valueIdList(final String page, final String limit, final String sort, final String order, final String valueId) {
        return null;
    }

    @Override
    public List<MarketCollect> allSearchList(final String page, final String limit, final String sort, final String order, final String userId, final String valueId) {
        return null;
    }
}
